package com.android.videotest.music.ui.playlist;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.videotest.R;
import com.android.videotest.music.base.BaseMusicDialogFragment;

import java.util.List;

import butterknife.BindView;
import cn.jzvd.JZUtils;

public class PlayListDialog extends BaseMusicDialogFragment {
    public static PlayListDialog newInstance() {
        Bundle args = new Bundle();
        PlayListDialog fragment = new PlayListDialog();
        fragment.setArguments(args);
        return fragment;
    }
    private static final String TAG = "PlayListDialog-App";
    TextView tvRepeatState;
    TextView tvCollectionAll;
    ImageView ivClear;
    View view;
    ConstraintLayout constraintLayout2;
    RecyclerView recyclerView;
    private PlayListAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_play_list, container, false);
        mAdapter = new PlayListAdapter();
        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setAdapter(mAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.windowAnimations = R.style.DialogBottomAnimation;
        attributes.width = ViewGroup.MarginLayoutParams.MATCH_PARENT;
//        attributes.height = (int) (displayMetrics.heightPixels * 0.56);
        attributes.gravity = Gravity.BOTTOM;
//        attributes.setWindowAnimations(R.style.DialogBottomAnimation);
        window.setAttributes(attributes);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        JZUtils.hideSystemUI(getActivity());
    }

    @Override
    protected void onConnected(@NonNull MediaControllerCompat mediaController) {
        Log.d(this.getClass().getSimpleName() + "-App", "onConnected() called with: mediaController = [" + mediaController + "]");
    }

    @Override
    protected void onChildrenLoaded(@NonNull String parentId, @NonNull List<MediaBrowserCompat.MediaItem> children) {
        mAdapter.setData(children);
        Log.d(this.getClass().getSimpleName() + "-App", "onChildrenLoaded() called with: parentId = [" + parentId + "], children = [" + children + "]");
    }

    @Override
    protected void onDisconnected() {

    }

    @Override
    protected void onPlaybackStateChanged(PlaybackStateCompat state) {

    }

    @Override
    protected void onMetadataChanged(MediaMetadataCompat metadata) {
        Log.d(TAG, "onMetadataChanged: ");
    }
}
